package cn.edu.zafu.bigdata.x.yaojy;
import java.io.*;
public class RhymingWords {

    public static Reader reverse(Reader source) throws IOException {
        BufferedReader in = new BufferedReader(source);
        PipedWriter pipedOut = new PipedWriter();
        PipedReader pipedIn = new PipedReader(pipedOut);
        PrintWriter out = new PrintWriter(pipedOut);
        new ReverseThread(out, in).start();
        return pipedIn;
    }

    /**
     * 排序线程
     *
     * @param source 输入流
     * @return 输出流
     */
    public static Reader sort(Reader source) throws IOException {
        BufferedReader in = new BufferedReader(source);
        PipedWriter pipedOut = new PipedWriter();
        PipedReader pipedIn = new PipedReader(pipedOut);
        PrintWriter out = new PrintWriter(pipedOut);
        new SortThread(out, in).start();
        return pipedIn;
    }

    public static void main(String[] args) throws IOException {
        FileReader words = new FileReader("files/yaojy/words.txt");
        Reader rhymedWords = reverse(sort(words));
        BufferedReader in = new BufferedReader(rhymedWords);
        String word;
        while ((word = in.readLine()) != null) {
            System.out.println(word);
        }
        words.close();
        rhymedWords.close();
    }
}


